<?php

//date_default_timezone_set('Etc/UTC');
require 'phpmailer.lib.php';

function send_mail($file, $email) {
    try {
        //Create a new PHPMailer instance
        $mail = new PHPMailer();
        //Tell PHPMailer to use SMTP
        $mail->IsSMTP();
        //Set the hostname of the mail server
        $mail->Host = 'smtp.gmail.com';
        //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
        $mail->Port = 587;
        //Set the encryption system to use - ssl (deprecated) or tls
        $mail->SMTPSecure = 'tls';
        //Whether to use SMTP authentication
        $mail->SMTPAuth = true;
        //Username to use for SMTP authentication - use full email address for gmail
        $mail->Username = "jualan.rider@gmail.com";
        //Password to use for SMTP authentication
        $mail->Password = "qeasdw123";
        //Set who the message is to be sent from
        $mail->SetFrom('jualan.rider@gmail.com', 'Jualan Rider Onlie');
        //Set who the message is to be sent to
        $mail->AddAddress($email);
        //Set the subject line
        $mail->Subject = "Nota Pembelian Jualan Rider";

        $body = file_get_contents($file);
        $body = preg_replace('/\\\\/', '', $body); //Strip backslashes
        $mail->MsgHTML($body);
        $mail->IsHTML(true); // send as HTML
        $mail->Send();
        echo 'Message has been sent.';
    } catch (phpmailerException $e) {
        echo $e->errorMessage();
    }
}

?>
